package com.krstin.designpattern.dependenceInversionPrinciple.implement2;

public class Example2 {

    public static void main(String[] args) {
        Switch s = new GeneralSwitch(new TV());
        s.open();
        Switch t = new GeneralSwitch(new TV());
        t.open();
    }

}


/**
 * 开关
 */
interface Switch {

    void open();

}

/**
 * 电器
 */
interface Electrice {

    public void start();

}

/**
 * 普通开关
 */
class GeneralSwitch implements Switch {

    private Electrice electrice;

    public GeneralSwitch(Electrice electrice) {
        this.electrice = electrice;
    }

    public void open() {
        System.out.println("普通开关");
        this.electrice.start();
    }

}

/**
 * 超级开关
 */
class SuperSwitch implements Switch {

    private Electrice electrice;

    public SuperSwitch(Electrice electrice) {
        this.electrice = electrice;
    }

    public void open() {
        System.out.println("超极开关");
        this.electrice.start();
    }
}


class TV implements Electrice {
    public void start() {
        System.out.println("开启了电视");
    }
}


